﻿@*
    配置
*@
@using NewLife;
@using System.ComponentModel;
@using System.Reflection;
@using NewLife.Reflection;
@using XCode;
@{
    var obj = (Object)Model;
    var list = ViewBag.Fields as IList<DataField>;
    var dic = list
        .GroupBy(e => e.Category + "")
        .ToDictionary(e => e.Key, e => e.ToList());
}

<div class="row m-0">
    <div class=" col-xl-3 col-lg-4">
        <div class="card  pb-lg-20">
            <div class="card-header">
                <h4 class="card-title text-muted">系统选项</h4>
            </div>

            <div class="text-center col-md-12 cube-flex-con cube-flex-items">
                @await Html.PartialAsync("_Object_Config_Nav", obj)
            </div>

        </div>

    </div>
    <div class="col-xl-9 col-lg-8">
        @using (Html.BeginForm("Update", null))
        {
            <div class="card mb-5 mb-xl-10">

                <div class="card-header">
                    <h4 class="card-title text-muted"></h4>
                    <div class="card-toolbar">
                        <button type="submit" class="btn btn-sm btn-outline btn-outline-dashed btn-outline-info btn-active-light-info align-self-center me-2"><i class="fas fa-save text-info"></i><strong>保存</strong></button>
                        <button type="button" class="btn btn-sm btn-outline btn-outline-dashed btn-outline-default btn-active-light align-self-center" onclick="history.go(-1);"><i class="fas fa-reply"></i><strong>取消</strong></button>

                    </div>
                </div>

                <div class="card-body p-9 pt-2">


                    @Html.AntiForgeryToken()
                    @Html.ValidationSummary(true)
                    @foreach (var item in dic)
                    {
                        if (dic.Count > 1)
                        {
                            <div class="card-header cursor-pointer p-0 border-0 pt-8 pb-5">
                                <div class="row">
                                    <div class="col-auto me-auto">
                                        <h5 class="card-title text-muted">@item.Key</h5>
                                    </div>
                                </div>

                            </div>
                        }
                        foreach (var pi in item.Value)
                        {
                            var name = pi.Name;
                            var val = obj.GetValue(name);
                            var dis = pi.DisplayName;
                            var des = pi.Description;
                            var dataSource = pi.DataSource;

                            <div class="row mb-1 pt-1">
                                <label class="col-lg-3 fw-bold text-muted">@dis</label>
                                <div class="col-lg-4">
                                    @if (dataSource != null)
                                    {
                                        @await Html.PartialAsync("_Form_Type_DropDownList", new ListBoxModel(name, dataSource(null, pi), val))
                                    }
                                    else
                                    {
                                        @await Html.PartialAsync("_Form_Editor_Item", new ItemModel(name, val, pi.Type))
                                    }
                                    <span class="fw-bolder fs-6 text-dark"></span>
                                </div>
                                <label class="col-lg-5 text-muted fs-10">@des</label>
                            </div>
                        }

                        <div class="border-bottom pt-5"></div>
                    }
                    @if (this.Has(PermissionFlags.Update))
                    {
                        <div class="clearfix form-actions col-sm-12 col-md-12 mt-10">
                            <label class="control-label col-xs-3 col-sm-3 col-md-3"></label>
                            <button type="submit" class="btn btn-sm btn-outline btn-outline-dashed btn-outline-info btn-active-light-info align-self-center me-2"><i class="fas fa-save text-info"></i><strong>保存</strong></button>
                            <button type="button" class="btn btn-sm btn-outline btn-outline-dashed btn-outline-default btn-active-light align-self-center" onclick="history.go(-1);"><i class="fas fa-reply"></i><strong>取消</strong></button>

                        </div>
                    }



                </div>

            </div>
        }

    </div>
</div>


